// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/testing/gtest_utils.h>
#include <pollux/testing/functions/prestosql/function_base_test.h>

using namespace kumo::pollux::test;

namespace kumo::pollux::functions {
namespace {

class MapNormalizeTest : public test::FunctionBaseTest {};

TEST_F(MapNormalizeTest, basic) {
  auto data = make_row_vector({
      make_map_vector_from_json<std::string, double>({
          "{\"a\": 1.0, \"b\": 2.0, \"c\": 2.0}",
          "{\"a\": 2.0, \"b\": 2.0, \"c\": null, \"d\": 1.0}",
          "{\"a\": 1.0, \"b\": -1.0, \"c\": null, \"d\": 0.0}",
          "{\"a\": null, \"b\": null}",
          "{}",
      }),
  });

  auto result = evaluate("map_normalize(c0)", data);

  auto expected = make_map_vector_from_json<std::string, double>({
      "{\"a\": 0.2, \"b\": 0.4, \"c\": 0.4}",
      "{\"a\": 0.4, \"b\": 0.4, \"c\": null, \"d\": 0.2}",
      "{\"a\": Infinity, \"b\": -Infinity, \"c\": null, \"d\": NaN}",
      "{\"a\": null, \"b\": null}",
      "{}",
  });

  assertEqualVectors(expected, result);
}

} // namespace
} // namespace kumo::pollux::functions
